home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / SmallTalk / Autoload.st < prev    next >
Text File  |  1995-08-25  |  2KB  |  74 lines

  1. "======================================================================
  2. |
  3. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  4. | Written by Steve Byrne.
  5. |
  6. | This file is part of GNU Smalltalk.
  7. |
  8. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  9. | under the terms of the GNU General Public License as published by the Free
  10. | Software Foundation; either version 1, or (at your option) any later version.
  11. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  12. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  14. | details.
  15. | You should have received a copy of the GNU General Public License along with
  16. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  17. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  18. |
  19.  ======================================================================"
  20.  
  21. "
  22. |     Change Log
  23. | ============================================================================
  24. | Author       Date       Change 
  25. | sbb         16 Feb 92      Created in the 1.1 timeframe
  26. |
  27. "
  28.  
  29. Object subclass: #Autoload
  30.        instanceVariableNames: 'className fileName'
  31.        classVariableNames: ''
  32.        poolDictionaries: ''
  33.        category: 'Cool hacks'
  34. !
  35.  
  36. Autoload comment:
  37. 'I am not a part of the normal Smalltalk kernel class system.  I provide the
  38. ability to do late-loading or "on demand loading" of class definitions.
  39. Through me, you can define any class to be loaded when any message is sent to
  40. the class itself (such as to create an instance).' !
  41.  
  42. !Autoload class methodsFor: 'instance creation'!
  43.  
  44. class: classNameString from: fileNameString
  45.     ^Autoload new autoloadInitClass: classNameString 
  46.           initFile: fileNameString
  47. !!
  48.  
  49.  
  50. !Autoload methodsFor: 'accessing'!
  51.  
  52. doesNotUnderstand: aMessage
  53.     | s |
  54.     Smalltalk removeKey: className.
  55.     FileStream fileIn: fileName.
  56.     ^aMessage reinvokeFor: (Smalltalk at: className
  57.                       ifAbsent: [ ^Autoload error: 
  58. 'Autoloaded file should have defined class "', className, '" but didn''t' ])
  59. !!
  60.  
  61.  
  62.  
  63. !Autoload methodsFor: 'private'!
  64.  
  65. autoloadInitClass: aClassName initFile: aFileName
  66.     className _ aClassName asSymbol.
  67.     Smalltalk at: className put: self.
  68.     fileName _ aFileName.
  69. !!
  70.  
  71. Autoload superclass: nil!    "force undefined methods"
  72.